package com.hakim.wfb.admin.filter;

import com.hakim.wfb.admin.enums.ErrorCodeEnum;
import com.hakim.wfb.bean.Menu;
import com.hakim.wfb.dao.MenuDao;
import com.hkfs.fundamental.api.data.ResultEx;
import com.hkfs.fundamental.validate.ValidateFilter;
import com.hkfs.fundamental.validate.annotaion.ValidateFilterBean;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotNull;

/**
 *
 */
@ValidateFilterBean
public class DeleteMenuFilter extends ValidateFilter<DeleteMenuFilter.DeleteMenuFilterParam> {

    @Autowired
    private MenuDao menuDao;

    @Override
    protected void prcoess(DeleteMenuFilterParam param, ResultEx resultEx){
        Menu menu = new Menu();
        menu.setParentId(param.getId());
        int count = menuDao.count(menu);
        if(count > 0){
            resultEx.makeResult(ErrorCodeEnum.MENU_HAS_CHILD.getCode(), ErrorCodeEnum.MENU_HAS_CHILD.getMessage());
            return;
        }
        resultEx.makeSuccessResult();
    }
    public static class DeleteMenuFilterParam{
        @NotNull(message = "菜单ID不能为空")
        private Long id;

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }
    }
}
